﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 玩家行操作为
/// 在每帧调用，若GetAction则调用Act
/// </summary>
public abstract class IAction {
    protected Rigidbody rig;
    protected Animator animator;
    protected Transform trans;
    public PlayerAttr mva;
    public IAction() { }
    public IAction(Rigidbody rig, Animator animator, Transform trans, PlayerAttr mva)
    {
        this.rig = rig;
        this.animator = animator;
        this.trans = trans;
        this.mva = mva;
    }

    public IAction(PlayerController comp):this(comp.GetComponent<Rigidbody>(), comp.GetComponentInChildren<Animator>(), comp.transform,comp.mva)
    {}

    public abstract void GetAction();
    public virtual void Init() { }
    public virtual void Act() { }
    /// <summary>
    /// 水平移动
    /// </summary>
    /// <param name="isLeft"></param>
    protected void HoriMove(bool isLeft)
    {
        mva.LookAtLeft = isLeft;
        Vector3 dir = Vector3.right;
        if (isLeft)
        {
            dir = -dir;
            if (rig.velocity.x>-mva.rigSpeed)
            {
                rig.AddForce(dir * mva.force);
            }
        }
        else
        {
            if (rig.velocity.x<mva.rigSpeed)
            {
                rig.AddForce(dir * mva.force);
            }
        }
        trans.position += dir * mva.trSpeed * Time.deltaTime;
    }
}
